package com.nmgs.config;


import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.Map;


public class MapAdapter extends XmlAdapter<String, Map<String, Object>> {
    @Override
    public Map<String, Object> unmarshal(String v) throws Exception {
        XStream objXStream = new XStream(new DomDriver());
        return (Map<String,Object>) objXStream.fromXML(v);
    }

    @Override
    public String marshal(Map<String, Object> v) throws Exception {
        XStream objXStream = new XStream();
        return objXStream.toXML(v);
    }

//
//    @Override
//    public MapConvertor marshal(Map<String, Object> map) throws Exception {
//        MapConvertor convertor = new MapConvertor();
//        for (Map.Entry<String, Object> entry : map.entrySet()) {
//            MapConvertor.MapEntry e = new MapConvertor.MapEntry(entry);
//            convertor.addEntry(e);
//        }
//        return convertor;
//    }
//
//    @Override
//    public Map<String, Object> unmarshal(MapConvertor map) throws Exception {
//        Map<String, Object> result = new HashMap<String, Object>();
//        for (MapConvertor.MapEntry e : map.getEntries()) {
//            result.put(e.getKey(), e.getValue());
//        }
//        return result;
//    }
}